<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //构造函数，原型函数
    //构造函数的参数
    function Person(name,age){
        var legs = 2;//内部的变量在外部没有办法直接读取
        //对象内部定义的函数没有办法在外部（实例化对象）直接读取
        function foo(){
            alert('我是对象内部的函数')
        }

        this.name = name;
        this.age = age;
        this.say = function(){
            alert(this.name)
        }
        this.showLegs = function(){
            return legs
        }
        this.setLegs = function(v){
            var reg = /^[012]$/;
            if (reg.test(v)){
                legs = v
            } else {
                alert('请不要开玩笑')
            }

        }
    }

    var user = new Person('frank',20);
    var user2 = new Person('tom',30);
    user.age = 'adfad';


</script>
</body>
</html>